home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
010
/
blit.arc
/
ADDOBS.C
next >
Wrap
Text File
|
1985-05-23
|
4KB
|
135 lines
/*
* name: addobs
*
* description: add obscured rectangle argr to obscured list op
* of layer lp, subdividing obscured portions
* of layers as necessary.
*
* synopsis: boolean addobs (op, argr, newr, lp)
* struct obscured *op;
* struct rectangle argr;
* struct rectangle newr;
* struct layer *lp;
*
* globals: none.
*
* calls: rectxrect (rectxrect.c)
* addobs (addobs.c)
* addrect (addrect.c)
* balloc (balloc.c)
* malloc (libc)
* bitblt (bitblt.c)
*
* called by: newlayer (newlayer.c)
* addobs (addobs.c)
*/
#include "layers.h"
boolean addobs (op, argr, newr, lp)
struct obscured *op;
struct rectangle *argr; /* struct obscured rectangle */
struct rectangle *newr; /* complete rectangle of new layer */
struct layer *lp; /* layer op belongs to */
{
struct obscured *newop;
struct rectangle r;
struct bitmap *bp;
struct rectangle temp;
struct bitmap *balloc ();
char *malloc ();
/* r = *argr; */ /* argr will be unchanged through
addobs() */
r.origin.x = argr -> origin.x;
r.origin.y = argr -> origin.y;
r.corner.x = argr -> corner.x;
r.corner.y = argr -> corner.y;
if (rectxrect (&r, newr)) {
/*
* this is much like layerop()
*/
if (r.origin.y < newr -> origin.y) {
/*
* temp = piece of r below newr;
*/
temp.origin.x = r.origin.x;
temp.origin.y = r.origin.y;
temp.corner.x = r.corner.x;
temp.corner.y = newr -> origin.y;
(void) addobs (op, &temp, newr, lp);
r.origin.y = newr -> origin.y;
}
if (r.corner.y > newr -> corner.y) {
/*
* temp = piece of r above newr;
*/
temp.origin.x = r.origin.x;
temp.corner.x = r.corner.x;
temp.corner.y = r.corner.y;
temp.origin.y = newr -> corner.y;
(void) addobs (op, &temp, newr, lp);
r.corner.y = newr -> corner.y;
}
if (r.origin.x < newr -> origin.x) {
/*
* temp = piece of r to the left of newr;
*/
temp.origin.x = r.origin.x;
temp.origin.y = r.origin.y;
temp.corner.y = r.corner.y;
temp.corner.x = newr -> origin.x;
(void) addobs (op, &temp, newr, lp);
r.origin.x = newr -> origin.x;
}
if (r.corner.x > newr -> corner.x) {
/*
* temp = piece of r to the right of newr;
*/
temp.origin.y = r.origin.y;
temp.corner.x = r.corner.x;
temp.corner.y = r.corner.y;
temp.origin.x = newr -> corner.x;
(void) addobs (op, &temp, newr, lp);
r.corner.x = newr -> corner.x;
}
/*
* r is now contained in rectangle of new layer
*/
if ((r.origin.x == argr -> origin.x) &&
(r.origin.y == argr -> origin.y) &&
(r.corner.x == argr -> corner.x) &&
(r.corner.y == argr -> corner.y)) {
(void) addrect (&r, op -> ob_obs);
return (false); /* no subdivision */
}
(void) addrect (&r, op -> ob_obs);
}
bp = balloc (&r);
/*
* newop = new struct obscured
*/
newop = (struct obscured *) malloc ((unsigned) sizeof (struct obscured));
/*
* copy the subdivided portion of the image
*/
(void) bitblt (op -> ob_bmap, &r, bp, &(bp -> bm_rect.origin), null, s);
newop -> ob_bmap = bp;
newop -> ob_rect.origin.x = r.origin.x;
newop -> ob_rect.origin.y = r.origin.y;
newop -> ob_rect.corner.x = r.corner.x;
newop -> ob_rect.corner.y = r.corner.y;
newop -> ob_obs = op -> ob_obs;
/*
* link newop into end of lp -> obs
*/
if (lp -> ly_endobs != null)
lp -> ly_endobs -> ob_next = newop;
else
lp -> ly_obs = newop;
newop -> ob_prev = lp -> ly_endobs;
newop -> ob_next = null;
lp -> ly_endobs = newop;
return (true); /* subdivision */
}